//
//  CommonUtils.swift
//  xgwjinterconnection
//
//  Created by WangWeiShuo on 2025/8/19.
//
import Foundation

struct CommonUtils{
    // 屏幕尺寸获取
//        static var screenSize: CGRect {
//            UIScreen.main.bounds.size
//        }
    static func parseWiFi(from urlString: String?) -> (ssid: String?, pwd: String?) {
        guard let url = URL(string: urlString!),
              let components = URLComponents(url: url, resolvingAgainstBaseURL: false),
              let queryItems = components.queryItems else { return (nil, nil) }
        
        let dict = Dictionary(uniqueKeysWithValues: queryItems.compactMap { item in
            item.value != nil ? (item.name, item.value!) : nil
        })
        
        return (dict["ssid"], dict["pwd"])
    }
    
    
}


extension String {
    /// 截取指定位置范围的子串（位置从1开始）
    func substring(from startPos: Int, to endPos: Int) -> String {
        guard startPos >= 1, endPos >= startPos, endPos <= count else {
            return "" // 越界时返回空（可根据需求调整）
        }
        let start = index(startIndex, offsetBy: startPos - 1)
        let end = index(startIndex, offsetBy: endPos)
        return String(self[start..<end])
    }
}
